﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sunimage.Spjg.BLL;
using Sunimage.Spjg.Web.Helper;

namespace Sunimage.Spjg.Web.Admin
{
    public partial class BulletinEdit : System.Web.UI.Page
    {
        BulletinBl bulletinBl = new BulletinBl();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request["id"]);

                Common.Bulletin bulletin = bulletinBl.GetById(id);
                tbxDate.Text = bulletin.CreateTime.ToShortDateString();
                tbxTitle.Text = bulletin.Title;
                tbxContent.Text = bulletin.Content;

            }
        }

        protected void btnSaveNewUser_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);

            Common.Bulletin bulletin = bulletinBl.GetById(id);

            bulletin.CreateTime = DateTime.Now;
            bulletin.Title = tbxTitle.Text;
            bulletin.Content = tbxContent.Text;

            try
            {
                bulletinBl.Update(bulletin);
                //Response.Redirect("Users.aspx");
                MessageHelper.RegShowJSAjax(btnSaveNewUser, "修改公告成功", this.Page);
            }
            catch (ApplicationException excp)
            {
                AlertHelper.ShowError("发生错误，请联系系统管理员", this.Page);
            }
        }

        protected void btnCancelNewCommercer_Click(object sender, EventArgs e)
        {
            Response.Redirect("Bulletin.aspx");
        }
    }
}